<?php
namespace app\index\model;

use think\facade\Db;
use app\common\model\Common;


class UserChild extends Common
{
    /**
     * 直接访问user child
     * @param $post
     * @param $user_id
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function tableDataChild($post)
    {
        $list_rows  = $post['limit'] ?? config('paginate.list_rows');
        $page       = $post['page'] ?? config('paginate.page');

        $where =[];
        if(isset($post['user_token']) && !empty($post['user_token'])){
            $where[] = ['user_token', 'like', '%' . trim($post['user_token']) . '%'];
        }
        if(isset($post['card_num']) && !empty($post['card_num'])){
            $where[] = ['c.card_num', 'like', '%' . trim($post['card_num']) . '%'];
        }
        $list = Db::name('user_child')->alias('uc')
            ->leftJoin("cards c", "c.child_num=uc.child_num")
            ->field('uc.* , c.card_num,c.balance,c.account_balance')
            ->where($where)
            ->order('uc.id desc')
            ->paginate(['list_rows' => $list_rows, 'page' => $page])
            ->toArray();

        return $result = [
            'code'  => 0,
            'msg'   => lang('get info success'),
            'data'  => $list['data'],
            'count' => $list['total'],
        ];
    }
}